package com.framework.common.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class HttpContextUtils {

	public static final String USER_KEY = "uid";

	public static final String REQUEST_PLATFORM = "request_platform";

	public static final String MCN_GUILD_ID = "mcn_guild_id";

	public static HttpServletRequest getHttpServletRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
	}

	public static Object getHttpServletRequestHeaderValue(String name) {
		return getHttpServletRequest().getAttribute(name);
	}


	/**
	 * 获取当前的 UID
	 * @return
	 */
	public static Long getHttpServletRequestHeaderUserid() {
		return (Long) HttpContextUtils.getHttpServletRequestHeaderValue(USER_KEY);
	}

	/**
	 * 获取当前的 UID
	 * @return
	 */
	public static String getHttpServletRequestHeaderPlatform() {
		return (String) HttpContextUtils.getHttpServletRequestHeaderValue(REQUEST_PLATFORM);
	}

	/**
	 * 获取当前的 GuildId
	 * @return
	 */
	public static Integer getHttpServletRequestHeaderMcnGuildId() {
		return (Integer) HttpContextUtils.getHttpServletRequestHeaderValue(MCN_GUILD_ID);
	}
}
